const conn = require('../../libs/DB/Conn');
const utils = require('../../libs/Utils');
module.exports = async function (params) {

    if (params.loginName && params.userName) {
        let checkUserSql = `SELECT
                          count(*) num
                           FROM
                            user_file uf                         
                           WHERE login_name = ? AND delete_sign = 1`;
        let queryResult = await conn(checkUserSql, [params.loginName]);
        if (queryResult[0].num > 0) {
            return {success: false, message: '登录名已存在'}
        } else {
            let insertObj = {
                login_name: params.loginName,
                password: utils.encrypt("123456"),
                user_name: params.userName,
                agent_id: params.agentId,
                group_id: 3,
                mobile: params.mobile,
            };
            let insertSql = `INSERT INTO user_file SET ?`;
            await conn(insertSql, [insertObj]);
            return {success: true, message: '添加成功'}
        }
    } else {
        return {success: false}
    }
};